package com.xiaoshuidi.cloud.module.rooms.service.impl;

import cn.hutool.core.util.StrUtil;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.area.vo.RoomAreaResp;
import com.xiaoshuidi.cloud.module.rooms.convert.area.RoomAreaConvert;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomArea;
import com.xiaoshuidi.cloud.module.rooms.repository.RoomAreaRepository;
import com.xiaoshuidi.cloud.module.rooms.service.RoomAreaService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author Feng
 * @date 2023/5/8
 */
@Service
@RequiredArgsConstructor
public class RoomAreaServiceImpl implements RoomAreaService {

    private final RoomAreaRepository roomAreaRepository;

    @Override
    public List<String> queryDistinctDistrict(String city) {
        List<String> list = roomAreaRepository.distinctDistrict(city);
        return list.stream().filter(s -> StrUtil.isNotEmpty(s)).collect(Collectors.toList());
    }

    @Override
    public List<String> queryDistinctBlock(String city, String district) {
        List<String> list = roomAreaRepository.distinctBlock(city, district);
        return list.stream().filter(s -> StrUtil.isNotEmpty(s)).collect(Collectors.toList());
    }

    @Override
    public List<RoomAreaResp> queryList(String city, String district, String street, String name) {
        List<RoomArea> list = roomAreaRepository.list(city, district, street, name);
        List<RoomAreaResp> responses = RoomAreaConvert.INSTANCE.convert(list);
        return responses;
    }
}
